package com.baomidou.springboot.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.springboot.entity.Health;
import com.baomidou.springboot.mapper.HealthMapper;
import com.baomidou.springboot.service.HealthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 关于我们 服务实现类
 * </p>
 *
 * @author QQQ
 * @since 2018-06-19
 */
@Service
public class HealthServiceImpl implements HealthService {

    @Autowired
    private HealthMapper healthMapper;

    @Override
    public void save(Health health) {
        health.setCreateDate(new Date());
        healthMapper.insert(health);
    }

    @Override
    public void delete(String id) {
        healthMapper.deleteById(id);
    }

    @Override
    public Health edit(String id) {
        return healthMapper.selectById(id);
    }

    @Override
    public void update(Health health) {
        health.setModifyDate(new Date());
        healthMapper.updateById(health);
    }

    @Override
    public Health view(String id) {
        return healthMapper.selectById(id);
    }

    @Override
    public Page<Health> list(Page<Health> page, String search) {
        if (0 == page.getSize()) {
            page.setSize(10);
        }
        if (0 == page.getCurrent()) {
            page.setCurrent(1);
        }
        List<Health> healthList = healthMapper.findByDateDesc(page, search);
        page.setRecords(healthList);
        return page;
    }

    @Override
    public void deleteBatch(List<String> ids) {
        if (null == ids) {
            return;
        }
        healthMapper.deleteBatchIds(ids);
    }

    @Override
    public Health findById(String id) {
        return healthMapper.selectById(id);
    }

    @Override
    public List<Health> findBySort() {
        return healthMapper.findBySort();
    }
}
